package interviewClassic150;

public class LengthOfLastWord {
    public int lengthOfLastWord(String s) {
        char[] chars = s.toCharArray();
        int i = chars.length - 1;
        while (i >= 0 && chars[i] == ' ') i--;
        int res = 0;
        while (i >= 0 && chars[i] != ' ') {
            res++;
            i--;
        }
        return res;
    }
}
